<%--
  Created by IntelliJ IDEA.
  User: Ouka
  Date: 2019/4/24
  Time: 15:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<form action="${pageContext.request.contextPath}/upload" method="post" enctype="multipart/form-data">

    <input type="text" name="username" placeholder="请输入姓名"/></br>
    <div id="file">
        <div><input type="file" name="file"/><a href="" onclick="return del(this)">删除</a></div>
    </div>

    <input type="button" onclick="add()" value="添加文件"/>
    <input type="submit" value="上传文件"/></br>
    <a href="${pageContext.request.contextPath}/listfile">文件列表</a>

</form>
<script type="text/javascript">
    var n = 1;

    function add() {
        var mydiv = document.createElement("div");
        var myinput = document.createElement("input");
        var mya = document.createElement("a");
        myinput.type = "file";
        myinput.name = "file" + n;
        mya.href = "javascript:viod(0)"
        mya.onclick = function () {
            document.getElementById("file").removeChild(this.parentNode);
        }
        n++;
        mya.innerHTML = "删除";
        mydiv.appendChild(myinput);
        mydiv.appendChild(mya);
        document.getElementById("file").appendChild(mydiv);
    }

    function del(o) {
        document.getElementById("file").removeChild(o.parentNode);
        return false;
    }

</script>

</body>
</html>
